package com.fengye.algorithms.leecode;

import java.util.Scanner;

public class StringZNMain06 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in) ;
        while (in.hasNext()) {
            String s = in.next();
            int numRows = in.nextInt();
            System.out.println(convert2(s, numRows));

        }
    }

    public static String convert2(String s, int num) {
        if(num == 1) {
            return s;
        }
        if(s.length() <= 2) {
            return s;
        }
        if(s.length() <= num) {
            return s;
        }
        int d = num+num-2;
        int dn = s.length()%d ==0 ? s.length()/d : s.length()/d + 1;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<num;i++) {
            for(int j=0;j<dn && (i+j*d) < s.length();j++){
                if(i==0 || i == num-1) {
                    sb.append(s.charAt(i + j * d));
                }
                if(i>0 && i< num-1) {
                    sb.append(s.charAt(i + j * d));
                    int t = (j+1) * d-i;
                    if(t<s.length()) {
                        sb.append(s.charAt(t));
                    }
                }
            }
        }

        return sb.toString();
    }

    public static String convert(String s,int num){
        if(num == 1) {
            return s;
        }
        if(s.length() <= 2) {
            return s;
        }
        if(s.length() <= num) {
            return s;
        }
        char[] chars = s.toCharArray();
        int d = num+num-2;
        int n = s.length() % d;
        boolean flag = n==0;
        int high = flag ? s.length()/d : s.length()/d + 1;
        int col = high * (num-1);
        if(!flag) {
           col = (high-1) * (num-1) + 1;
           if(n>num) {
               col = col + n - num;
           }
        }

        char[][] resChar = new char[num][col];
        for(int i=0;i<num;i++) {
            for (int j = 0; j < col; j++) {
                resChar[i][j] = ' ';
            }
        }
        for(int j=0;j<high;j++) {
            for (int i = 0; i < d && (i + j*d)<chars.length; ) {
                if(i<num) {
                    resChar[i][j*(num-1)] = chars[j * d + i];
                    i++;
                } else {
                    for (int a = 1; a <= num - 2; a++) {
                        resChar[(i-a)-a][j*(num-1)+a] = chars[j * d + i];
                        i++;
                        if(j * d + i >= chars.length) {
                            break;
                        }
                    }
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        for(int i=0;i<num;i++) {
            for(int j=0;j<col;j++) {
                if(resChar[i][j] != ' ') {
                    sb.append(resChar[i][j]);
                }
            }
        }

        return sb.toString();
    }
}